package me.sdau.spider.openapi.configs;

import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.net.InetAddress;
import java.net.UnknownHostException;

@Configuration
public class ElasticSearchConfig {

    @Bean
    public TransportClient transportClient() throws UnknownHostException {
        InetSocketTransportAddress node = new InetSocketTransportAddress(
                InetAddress.getByName("172.16.23.13"),
                9303);

        Settings settings = Settings.builder()
                /*.put("cluster.name", "elasticsearch")*/
                .put("cluster.name", "esfyb_cluster")
                .build();

//        TransportClient client = new PreBuiltTransportClient(settings);
        TransportClient client = TransportClient
                .builder()
                .settings(settings)
                .build();
        client.addTransportAddress(node);

        return client;
    }
}
